Struktur per Programm anlegen

Im Customizing zu den Nachrichtenarten werden die Tabellen zu den Zugriffsfolgen generiert. Mit dem folgenden Programm können Sie so eine automatische Generierung nachvollziehen.

*---------------------------------------------------------------------*
* Report  Z_GEN_LAENDER
*---------------------------------------------------------------------*
* Erzeugen einer Dictionary-Struktur
* o Für jedes Land in der Ländertabelle, dessen Länderkürzel mit "D"
*   beginnt, wird ein Feldname angelegt beginnend mit LAND_
* o Die Struktur wird der Entwicklungsklasse aus dem Selektionsbild
*   zugeordnet
* o Die Struktur wird in einen Transportauftrag aufgenommen
*---------------------------------------------------------------------*

REPORT  z_GEN_LAENDER.

DATA lt_t005      TYPE STANDARD TABLE OF t005.
DATA ls_t005      TYPE                   t005.

PARAMETERS: p_tab TYPE tabname  DEFAULT 'Z_LAENDER',
            p_dcl type devclass default 'Z_VERKAUF'.

START-OF-SELECTION.

  PERFORM selection.
  PERFORM structure.
  PERFORM tadirentry.
  PERFORM transport.
  MESSAGE s000(vz) WITH 'Struktur wurde angelegt'.

*&---------------------------------------------------------------------*
*&      Form  selection
*&---------------------------------------------------------------------*
FORM selection.

*** Alle Länder, deren Kürzel mit D beginnt einlesen
  SELECT * FROM t005 INTO TABLE lt_t005
   WHERE land1 LIKE 'D%'.

*** Sort
  SORT lt_t005.

ENDFORM.                    "selection

*&---------------------------------------------------------------------*
*&      Form  structure
*&---------------------------------------------------------------------*
FORM structure.

  DATA ls_dd02v     TYPE dd02v.
  DATA ls_dd09l     TYPE dd09l.
  DATA lt_dd03p     TYPE STANDARD TABLE OF dd03p.
  DATA ls_dd03p     TYPE dd03p.

*** Struktur
  CLEAR ls_dd02v.
  ls_dd02v-tabname      = p_tab.
  ls_dd02v-ddlanguage   = 'D'.
  ls_dd02v-tabclass     = 'INTTAB'.
  ls_dd02v-ddtext       = 'Automatically generated structure'.
  ls_dd02v-applclass    = 'VIEW'.
  ls_dd02v-as4user      = sy-uname.
  ls_dd02v-as4date      = sy-datum.
  ls_dd02v-as4time      = sy-uzeit.
  ls_dd02v-exclass      = '3'.

*** Technische Einstellungen werden für eine Struktur nicht benötigt
  CLEAR ls_dd09l.

*** Felder
  CLEAR lt_dd03p.
  LOOP AT lt_t005 INTO ls_t005.
    CLEAR ls_dd03p.
    ls_dd03p-tabname    = p_tab.
    CONCATENATE 'LAND_' ls_t005-land1 INTO ls_dd03p-fieldname.
    ls_dd03p-position   = sy-tabix.
    ls_dd03p-rollname   = 'LAND1'.
    ls_dd03p-domname    = 'LAND1'.
    APPEND ls_dd03p TO lt_dd03p.
  ENDLOOP.

*** Struktur erzeugen
  CALL FUNCTION 'DD_TABL_PUT'
    EXPORTING
      dd02v_wa            = ls_dd02v
      dd09l_wa            = ls_dd09l
      put_state           = 'A'
      tabl_name           = p_tab
    TABLES
      dd03p_tab           = lt_dd03p
    EXCEPTIONS
      db_access_failure   = 1
      object_inconsistent = 2
      OTHERS              = 3.
  IF sy-subrc <> 0.
    WRITE: / 'Fehler bei DD_TABL_PUT', sy-subrc.
    STOP.
  ENDIF.

ENDFORM.                    "structure

*&---------------------------------------------------------------------*
*&      Form  tadirentry
*&---------------------------------------------------------------------*
FORM tadirentry.

  DATA lv_srcsystem TYPE srcsystem.
  DATA lv_obj_name  TYPE sobj_name.

*** Originalsystem
  lv_srcsystem = sy-sysid.
*** Name der Struktur:
  lv_obj_name = p_tab.

*** TADIR-Eintrag erzeugen
  CALL FUNCTION 'TR_TADIR_INTERFACE'
    EXPORTING
      wi_test_modus      = ' '
      wi_tadir_pgmid     = 'R3TR'
      wi_tadir_object    = 'TABL'
      wi_tadir_obj_name  = lv_obj_name
      wi_tadir_srcsystem = lv_srcsystem
      wi_tadir_author    = sy-uname
      wi_tadir_devclass  = p_dcl
      wi_set_genflag     = 'X'
    EXCEPTIONS
      OTHERS             = 25.
  IF sy-subrc <> 0.
    WRITE: / 'Fehler bei TR_TADIR_INTERFACE'.
    STOP.
  ENDIF.

ENDFORM.                    "tadirentry

*&---------------------------------------------------------------------*
*&      Form  transport
*&---------------------------------------------------------------------*
FORM transport.

*** Data
  DATA: iko200 TYPE ko200,
        iorder TYPE trkorr,
        itask  TYPE trkorr.

*** Object
  iko200-pgmid    = 'R3TR'.
  iko200-object   = 'TABL'.
  iko200-objfunc  = space.
  iko200-obj_name = p_tab.

*** Auftrag abfragen
  CALL FUNCTION 'TR_ORDER_CHOICE_CORRECTION'
    EXPORTING
      iv_category = 'SYST'
    IMPORTING
      ev_order    = iorder
      ev_task     = itask
    EXCEPTIONS
      OTHERS      = 3.
  IF sy-subrc <> 0.
    WRITE: / 'Fehler TR_ORDER_CHOICE_CORRECTION'.
    STOP.
  ENDIF.

*** Prüfen der Objekte
  CALL FUNCTION 'TR_OBJECT_CHECK'
    EXPORTING
      wi_ko200                = iko200
    EXCEPTIONS
      cancel_edit_other_error = 1
      show_only_other_error   = 2
      OTHERS                  = 3.
  IF sy-subrc <> 0.
    WRITE: / 'Fehler TR_OBJECT_CHECK'.
    STOP.
  ELSE.

*** Einfügen des Objektes in den Auftrag
    CALL FUNCTION 'TR_OBJECT_INSERT'
      EXPORTING
        wi_order                = itask
        wi_ko200                = iko200
      EXCEPTIONS
        cancel_edit_other_error = 1
        show_only_other_error   = 2
        OTHERS                  = 3.
    IF sy-subrc > 0.
      WRITE: / 'Fehler TR_OBJECT_INSERT'.
    ELSE.
      COMMIT WORK.
    ENDIF.
  ENDIF.

ENDFORM.                    "transport


Enno Wulff
Letzte Artikel von Enno Wulff (Alle anzeigen)